package lib.quasar.widget.dot;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import lib.quasar.widget.R;

public class DotView extends View {

    private int mColor = Color.TRANSPARENT;
    private final Paint mPaint = new Paint();

    public DotView(Context context) {
        super(context);
    }

    public DotView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DotView, 0, 0);
        mColor = a.getColor(R.styleable.DotView_dv_color, mColor);
        a.recycle();
    }

    public DotView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DotView, defStyleAttr, 0);
        mColor = a.getColor(R.styleable.DotView_dv_color, mColor);
        a.recycle();
    }

    @Override
    public void draw(Canvas canvas) {
        mPaint.setAntiAlias(true);
        mPaint.setColor(mColor);
        final float radius = getWidth() / 2f;
        canvas.drawCircle(radius, radius, radius, mPaint);
        super.draw(canvas);
    }
}
